package com.hk.rabbitmq.one;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author: dpb
 * @date: 2022/3/9
 */
public class Producer {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception{

        ConnectionFactory factory = new ConnectionFactory();

        factory.setHost("121.40.45.96");
        factory.setUsername("admin");
        factory.setPassword("123");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        String queueName = "s1";
        System.out.println(queueName);

        /**
         * 定义一个队列
         * 1、队列的名称
         * 2、
         */
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        String message = "hello RibbitMQ";
        channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
        System.out.println("消息发送完毕！");
    }
}
